$(document).ready(function() {
	MyObjectHHH = {
		infonumber : "",
		infoname : "",
		price : "",
		offset : 0,
		limit : 10,
		uid : $("#useridoflogin").val()
	}
	
	function getlist() {
		MyObjectHHH.infonumber = $("#infonumber").val();
		MyObjectHHH.infoname = $("#infoname").val();
		MyObjectHHH.price = $("#pirce").val();
	}

	/*This Is Huang To Pages O(∩_∩)O*/
	MyObjectogHHH = {
		url :Server+ "/ix/controllistport",
		uid:$("#useridoflogin").val(),
		infonumber:$("#infonumber").val(),
		infoname:$("#infoname").val(),
		price:$("#pirce").val(),
		offset : 0,
		limit : 10,
		haveuid : "",
		ishavesend : 1,
		boolean : false,
		type : "POST",
		dataType : "JSON",
		number : 1,
		AllCount : 0,
		nowp : 0,
		Callback : function(nowPage) {
			MyObjectogHHH.nowp = nowPage;
			MyObjectHHH.offset = nowPage-1;
			getlist();
			Myload(MyObjectHHH);
		}
	};

	function MyObjectogHHHofpageload() {
		$("#page").initPage((function() {
			$.ajax({
				"url" : Server+ "/ix/controllistport",
				"type" : MyObjectogHHH.type,
				"dataType" : MyObjectogHHH.dataType,
				"async" : MyObjectogHHH.boolean,
				"data" : MyObjectHHH,
				success : function(data) {
					MyObjectogHHH.AllCount = data.count;
				}
			});
			return MyObjectogHHH.AllCount;
		})(), MyObjectogHHH.number, MyObjectogHHH.Callback);
	}
	MyObjectogHHHofpageload();
	

	/*$("#findinfolist").click(function(){
		getlist();
		Myload(MyObjectHHH);
	})*/
	$("#listdiv")
		/*.change(function(){
			getlist();
			Myload(MyObjectHHH);
		})
		.keydown(function(){
			getlist();
			Myload(MyObjectHHH);
		})*/
		.bind('input', function() {
			getlist();
			MyObjectogHHHofpageload();
		});
})





function Myload(MyObjectHHH) {
	$.ajax({
		url :Server+  "/ix/controllistport",
		type : "POST",
		dataType : "JSON",
		data : MyObjectHHH,
		success : function(data) {
			var html = "";
			var htmlhead = '<tr>\
				<th></th>\
				<th>仪器编号</th>\
				<th>仪器名称</th>\
				<th>仪器负责人</th>\
				<th>状态</th>\
				<th>价格</th>\
				<th>操作</th>\
			</tr>';
			for (var i = 0; i < data.list.length; i++) {
				var pattern = '<tr style="height:92px">\
							<td>\
						<input type="checkbox" name="" id="" value="#4" />\
						<label><img src="images/icon35.png"/></label>\
					</td>\
					<td>#0</td>\
					<td>#1</td>\
					<td>#2</td>\
					<td>#3</td>\
					<td>#7</td>\
					<td>\
						<a onclick="findInfo(#5)">修改</a>\
						<a onclick="knowledge(#6, \'#8\')">上传仪器知识</a>\
					</td>\
				</tr>';
				var price = (data.list[i].siiPrice == null)?0:data.list[i].siiPrice;
				var unit = (data.list[i].siiUnit == null)?'元/天':data.list[i].siiUnit;
				html += pattern
					.replace("#0", data.list[i].siiNumber)
					.replace("#1", data.list[i].siiChineseName)
					.replace("#2", data.list[i].realname)
					.replace("#3", data.list[i].siiIStatus)
					.replace("#4", data.list[i].siiId)
					.replace("#5", data.list[i].siiId)
					.replace("#6", data.list[i].siiId)
					//.replace("#7", data.list[i].siiPrice+""+data.list[i].siiUnit)
					.replace("#7",price+unit)
					.replace("#8", data.list[i].siiChineseName);
			}

			$("#listtable").html(htmlhead + html);
			$(".mainList .content .right table td label").click(function() {
				if ($(this).siblings('input').is(':checked')) {
					$(this).find('img').attr('src', 'images/icon35.png');
					$(this).siblings('input').prop('checked', false);
				} else {
					$(this).find('img').attr('src', 'images/icon36.png');
					$(this).siblings('input').prop('checked', true);
				}
				;
			});
			$("#export").click(function() {
				var idStr="";
				var allIdStr="";
				 for(i=0;i<$('img').length;i++){
					if($('img').eq(i).attr("src")=="images/icon35.png"){
						allIdStr=allIdStr+$('img').eq(i).parent().prev().val()+","
					}
					if($('img').eq(i).attr("src")=="images/icon36.png"){
						idStr=idStr+$('img').eq(i).parent().prev().val()+","
					} 
				}
				if(idStr==""){
					//alert("请至少选择一条服务再导出");
					//return false;
					idStr=allIdStr;
				} 
				//window.location.href="http://localhost/insRelevant/insExportExcel?idStr="+idStr;
				window.location.href=Server+"/insRelevant/insExportExcel?idStr="+idStr;
			});
			$("#addTimeProject").click(function() {
				var idStr="";
				var allIdStr="";
				 for(i=0;i<$('img').length;i++){
					if($('img').eq(i).attr("src")=="images/icon36.png"){
						idStr=idStr+$('img').eq(i).parent().prev().val()+","
					} 
				}
				 idStr=idStr.substring(0,idStr.length-1);
				//window.location.href="http://localhost/insRelevant/insExportExcel?idStr="+idStr;
				if(idStr!=""){
					window.location.href="add18?insId="+idStr;
				}else{
					window.location.href="add18";
				}
			});
		},
	})
}



function findInfo(infoid){
	$(location).attr('href', 'lizisepuyimy16?iid=' + infoid);
}
function knowledge(infoid, ChineseName){
	$(location).attr('href', 'send_machine18_1?infoid=' + infoid + '&ChineseName=' + ChineseName);
}

